<template>
  <div>
    <el-dialog
      title="增加供应商分类"
      :visible.sync="visible"
      :modal-append-to-body="false"
      :close-on-press-escape="false"
      :close-on-click-modal="false"
      @close="closeDialog"
      
      width="500px"
    >
      <div class="warn">
        <p>
          <strong>说明:</strong>
          <br />标记*的必须录入数据的字段
        </p>
      </div>
      <div class="form"></div>
      <el-form ref="form" :model="submit" label-position="left" label-width="105px" size="mini">
        <el-form-item label="*分类名称">
          <el-input v-model="submit.name"></el-input>
        </el-form-item>
        <el-form-item label="*分类编码">
          <el-input v-model="submit.code"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="visible = false">取 消</el-button>
        <el-button type="primary" @click="Submit()">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import treeTable from "../../../multiplexing/treetable";
export default {
  components: { treeTable },
  props: {
    form: {
      style: Object
    }
  },
  data() {
    return {
      submit: {},
      visible: true,
      treeApp: {
        hackReset: false,
        visible: false,
        here_list: {},
        firstColumn: {
          name: "机构组织名",
          prop: "name",
          width: "300"
        }
      }
    };
  },
  methods: {
    Check() {
      if (
        this.submit.name == null ||
        this.submit.name == "" ||
        this.submit.code == null ||
        this.submit.code == "" 
      ) {
        this.$message.error("请录入必填数据的字段！");
        return false;
      }
      return true;
    },
    Submit() {
      window.console.log(this.submit);

      if (this.Check()) {
        this.$http.post("supplierClass/insert", this.submit).then(response => {
          if (response.data == "success") {
            this.$message({
              message: "添加完成",
              type: "success"
            });
            this.NeedRefresh();
            this.visible = false;
          }
        });
      }
    },
    closeDialog() {
      window.console.log("dfialog-close");
      this.$emit("dialog-close");
    },
    NeedRefresh() {
      this.$emit("refresh");
    },
    selectFather(node) {
      this.submit.orangeid = node.id;
      this.submit.orangename = node.name;
    },
    SureSelectOrange() {
      this.treeApp.visible = false;
    }
  },
  created() {
    // this.$http
    //   .post("orangetree/organename", { id: this.form.orangeid })
    //   .then(response => {
    //     this.submit.orangename = response.data;
    //   });
    // this.submit = JSON.parse(JSON.stringify(this.form));
  }
};
</script>

<style>
.form {
  margin-top: 20px;
}
</style>